<div class="widget">
	<div class="widget-header bg-blue">
		<i class="widget-icon icon-notebook"></i> 
		<span class="widget-caption"> 新增角色 </span>
		<div class="widget-buttons">
			<a href="javascript:void(0);" onclick="handlerCancel(this);" title="关闭"
				 data-toggle="dispose" data-refresh-table="#table-groups"> <i class="fa fa-times"></i> </a> 
		</div>
	</div>
	<div class="widget-body">
		<!-- TODO 基本信息 -->
		<div class="widget radius-bordered">
			<div class="widget-header">
				<i class="widget-icon icon-notebook"></i> 
				<span class="widget-caption"> 基本信息 </span>
			</div>
			<div class="widget-body editor-body-sm">
				<form class="form-horizontal form-editor form-editor-groups">
					<div class="row">
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label required" for="name">角色名称</label>
								<div class="col-sm-8">
									<input name="name" id="name" type="text" class="form-control" required="required">
								</div>
							</div>
						</div>
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label required" for="code">角色编码</label>
								<div class="col-sm-8">
									<input name="code" id="code" type="text" class="form-control" required="required">
								</div>
							</div>
						</div>
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label" for="sort">排序号</label>
								<div class="col-sm-8">
									<input name="sort" id="sort" type="text" class="form-control"> 
								</div>
							</div>
						</div>
					</div>

					<div class="widget-footer editor-footer-sm">
						<button type="button" class="btn btn-danger btn-sm" data-toggle="tooltip" data-placement="top" title="取消" onclick="handlerCancel(this);" data-refresh-table="#table-groups">
							<i class="glyphicon glyphicon-remove"></i>
						</button>
						<button type="button" class="btn btn-primary btn-sm" data-toggle="tooltip" data-placement="top" title="保存" onclick="handlerSubmit(this, '#editor-form-groups', '.form-editor-groups');">
							<i class="glyphicon glyphicon-ok"></i>
						</button>
					</div>
				</form>
			</div>
		</div>
		
		<!-- TODO 校区信息 -->
		<div class="widget radius-bordered hidden" id="viewer-panel-assets">
			<div class="widget-header">
				<i class="widget-icon icon-notebook"></i> 
				<span class="widget-caption"> 配置资源 </span>
			</div>
			<div class="widget-body editor-body-sm">
				<div id="tree" data-entity="com.app.miwawa.api.system.entity.Assets"></div>
				
				<div class="widget-footer editor-footer-sm">
						<button type="button" class="btn btn-danger btn-sm" data-toggle="tooltip" data-placement="top" title="取消" onclick="handlerCancel(this);" data-refresh-table="#table-groups">
							<i class="glyphicon glyphicon-remove"></i>
						</button>
						<button type="button" class="btn btn-primary btn-sm" data-toggle="tooltip" data-placement="top" title="保存" onclick="handlerTree(this);">
							<i class="glyphicon glyphicon-ok"></i>
						</button>
					</div>
			</div>
		</div>
	</div>
</div>

<!-- 提交表单 ========================================================= -->
<form id="editor-form-groups" action="/miwawa/default/common/save" method="post" 
			name="com.app.miwawa.api.system.entity.Groups" data-show-target="#viewer-panel-assets">
			<input type="hidden" name="bean['status']" value="0">
			<input type="hidden" name="bean['invalid']" value="F">
			<input type="hidden" name="bean['systemid']" value="297ebe0e53d648370153d64dbefc0002">
			<input type="hidden" name="bean['createDate']" value="0" id="createDate">
</form>
    
<script type="text/javascript">
<!--
	jQuery(function() {
		require(['moment','jquery.plugin.form','jquery.bootstrap.tree'],function(moment, form, tree){
			jQuery('#createDate').val(moment().format("YYYY-MM-DD"));
			
			form.tooltip("[data-toggle='tooltip']");
			
			tree.init("#tree", {
				url: "/miwawa/default/common/tree.json",
				querys: {
					"and": [{"operator":"EQ", "fieldName":"systemid", "fieldValue":"297ebe0e53d648370153d64dbefc0002"}],
					"order": [{"sort":"code", "order":"asc"}]
				}
			});
		});
	});
	
	function handlerTree(trigger){
		var params = [], nodes = jQuery('#tree').treeview('getChecked');
		var groupsid = jQuery("#editor-form-groups").data("com.app.miwawa.api.system.entity.Groups");
		
		for(var i in nodes){
			var node = nodes[i];
			params.push({
				"groupsid": groupsid,
				"assetsid": node.id,
				"assetspid": node.pid,
				"assetsCode": node.code,
				"assetsType": node.type,
				"status": "0",
				"invalid": "F"
			});
		}
		
		jQuery.ajaxsend({
			url: "/miwawa/default/common/save",
			data: {
				"entityClass": "com.app.miwawa.api.system.entity.Auths",
				"beans": params
			},
			success: function(data){
				if(data){
					jQuery(trigger).parent().hide();
				}
			}
		});
	}
//-->
</script>